package com.sunclouder.cactus.common.api.response;

import static com.sunclouder.cactus.common.api.response.ResponseCode.SUCCESS;

public class ResponseHelper {
    public static <T> ResponseBean<T> success(T data) {
        return new ResponseBean<>(SUCCESS.getCode(), SUCCESS.getMessage(), data);
    }

    public static <T> ResponseBean<T> success() {
        return success(null);
    }

    public static <T> ResponseBean<T> failure(int code, String message) {
        return new ResponseBean<>(code, message, null);
    }

    public static <T> ResponseBean<T> failure(ResponseCode code) {
        return new ResponseBean<>(code.getCode(), code.getMessage(), null);
    }

    public static <T> ResponseBean<T> failure(ResponseException e) {
        return failure(e.getCode());
    }
}
